﻿
/// <reference path="../../Plugin/datepicker/js/jquery.ui.datepicker.js" />
/// <reference path="../../Plugin/datepicker/css/jquery.ui.core.css" />
/// <reference path="../../Plugin/datepicker/css/jquery.ui.datepicker.css" />
/// <reference path="../../Plugin/datepicker/css/jquery.ui.theme.css" />
/// <reference path="../Pages/Product/BuyingGroup.js" />



//-----------------------------------------------------------
// Author:      thuphuong.tran
// Create Date: 28/10/2010
// Description: Xử lý show popup danh sach User tham gia nhóm mua
//-----------------------------------------------------------
ShowListUser = new function () {
    this.buyingGroupID = 0;
    this.m_objPageListUser = new VtcPaging("divListUserJoinPagingPopup", "ShowListUser.bindListUser", "pagingCss", 10, CONSTANT.PAGE_DISPLAY);
    this.m_idShowListUser = "divShowListUser";
    this.showPopup = function (_bgID) {
        this.buyingGroupID = _bgID;
        if ($("#" + this.m_idShowListUser).length == 0) {
            $("body").append("<div id='" + this.m_idShowListUser + "'></div>");
            $("#" + ShowListUser.m_idShowListUser).setTemplateURL("/Template/Popup/TrutienShop/ShowListUser.htm");
            $("#" + ShowListUser.m_idShowListUser).processTemplate(null);
            var top = (($(window).height() / 2) - ($("#divPopup_ShowListUser").outerHeight() / 2)) - 80;
            var left = (($(window).width() / 2) - ($("#divPopup_ShowListUser").outerWidth() / 2));
            if (top < 0) top = 0;
            if (left < 0) left = 0;
            // IE6 fix
            if ($.browser.msie && parseInt($.browser.version) <= 6) top = top + $(window).scrollTop();

            $("#divPopup_ShowListUser").css({
                top: top + 'px',
                left: left + 'px'
            });

            $(".content_info_left", "#divPopup_ShowListUser").css({
                'text-align': 'left',
                'width': 80 + 'px'
            });

            $(".content_info_right", "#divPopup_ShowListUser").css({
                'text-align': 'left',
                'width': 120 + 'px'
            });

            this.bindListUser(1, ShowListUser.m_objPageListUser.pageSize);
        }

        try {
            $("#divPopup_ShowListUser").draggable({ handle: $("#divPopup_ShowListUser .barpopup") });
            $("#divPopup_ShowListUser .barpopup").css({ cursor: 'move' });
        } catch (e) { /* requires jQuery UI draggables */ }


    };

    this.bindListUser = function (_cur) {
        $.ajax({
            type: "GET",
            url: "/Handler/TrutienShop/HandlerProduct.ashx",
            data: { buyingGroupID: ShowListUser.buyingGroupID, currentPage: _cur, pageSize: ShowListUser.m_objPageListUser.pageSize, t: "GetListUserJoinBuyingGroup" },
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            success: function (data) {
                $("#spTotalUserJoinBuyingGroupPopup").html('(' + data.TotalRecord.toString() + ')');
                $("#divListUserJoinPopup").setTemplateURL("/Template/Popup/TrutienShop/ShowListUserSub.htm");
                $("#divListUserJoinPopup").processTemplate(data);
                ShowListUser.setStyleRow("#divListUserJoinPopup");
                ShowListUser.m_objPageListUser.bindPaging(_cur, data.TotalRecord);
                if (data.TotalRecord <= ShowListUser.m_objPageListUser.pageSize) {
                    $("#divListUserJoinPagingPopup").attr('style', 'display:none');
                }
                else {
                    $("#divListUserJoinPagingPopup").attr('style', 'display:block');
                }

                var top = (($(window).height() / 2) - ($("#divPopup_ShowListUser").outerHeight() / 2));
                var left = (($(window).width() / 2) - ($("#divPopup_ShowListUser").outerWidth() / 2));
                if (top < 0) top = 0;
                if (left < 0) left = 0;
                // IE6 fix
                if ($.browser.msie && parseInt($.browser.version) <= 6) top = top + $(window).scrollTop();

                $("#divPopup_ShowListUser").css({
                    top: top + 'px',
                    left: left + 'px'
                });
            }
        });
    };


    this.convertStatusUser = function (_status) {
        if (_status == 1)
            return "Đặt mua";
        if (_status == 2)
            return "Đã trả Item vào game";
        if (_status == 3)
            return "Đã trả Item vào tủ đồ của người mua";
        if (_status == 4)
            return "Đã chuyển Item vào tủ đồ của người được tặng";
        if (_status == 5)
            return "Hoàn tiền";
        if (_status == -1)
            return "Lỗi Add Item vào Game";
    };

    this.close = function () {
        if ($("#" + this.m_idShowListUser).length != 0) {
            $("#" + this.m_idShowListUser).remove();
        }
    };

    this.setStyleRow = function (m_selParent) {
        var m_stt = 0;
        $('#divItem', m_selParent).each(function () {
            m_stt++;
            if ((m_stt % 2) == 0) {
                $(this.parentNode).addClass('even');
            }
            else {
                $(this.parentNode).addClass('odd');
            }
        });
    };

}